home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 26.zip / BS1 part 26 / C for beginners.adf / source / math3.c < prev    next >
C/C++ Source or Header  |  1978-01-17  |  814b  |  37 lines

  1. /* math3.c 4.5.5*/
  2. void main()
  3. {
  4.   float number1, number2, result;
  5.   char operator;
  6.   int error;
  7.  
  8.   printf("Input Format: Number, Operator, Number (no spaces)!\n");
  9.   scanf("%f%c%f", &number1, &operator, &number2);
  10.   error = 1;
  11.   if(operator == '+') /* Addition */
  12.        {
  13.      result = number1 + number2;
  14.    error = 0;
  15.     }
  16.   if(operator == '-') /* Subtraction */
  17.        {
  18.      result = number1 - number2;
  19.     error = 0;
  20.     }
  21.   if(operator == '*') /* Multiplication */
  22.       {
  23.      result = number1 * number2;
  24.      error = 0;
  25.    }
  26.   if(operator == '/') /* Division */
  27.       {
  28.      result = number1 / number2;
  29.      error = 0;
  30.    }
  31.   if(error == 1) /* None of the conditions above satisfied? */
  32.   printf("Wrong Operator %c!\n", operator);
  33. else
  34.   printf("%f %c %f = %f\n", number1, operator, number2, result);
  35. }
  36.  
  37.